package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.CharacterQuestTable;
import com.lineage.server.datatables.storage.CharacterQuestStorage;
import com.lineage.server.templates.CharQuest;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CharacterQuestReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final CharacterQuestStorage _storage = (CharacterQuestStorage)new CharacterQuestTable();
  
  private static CharacterQuestReading _instance;
  
  public static CharacterQuestReading get() {
    if (_instance == null)
      _instance = new CharacterQuestReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public Map<Integer, CharQuest> get(int char_id) {
    this._lock.lock();
    Map<Integer, CharQuest> tmp = null;
    try {
      tmp = this._storage.get(char_id);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void storeQuest(int char_id, int key, CharQuest value) {
    this._lock.lock();
    try {
      this._storage.storeQuest(char_id, key, value);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void storeQuest2(int char_id, int key, int value) {
    this._lock.lock();
    try {
      this._storage.storeQuest2(char_id, key, value);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void updateQuest(int char_id, int key, CharQuest value) {
    this._lock.lock();
    try {
      this._storage.updateQuest(char_id, key, value);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void delQuest(int char_id, int key) {
    this._lock.lock();
    try {
      this._storage.delQuest(char_id, key);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void delQuest2(int key) {
    this._lock.lock();
    try {
      this._storage.delQuest2(key);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void storeQuest(int char_id, int key, CharQuest value, int clear) {
    this._lock.lock();
    try {
      this._storage.storeQuest(char_id, key, value, clear);
    } finally {
      this._lock.unlock();
    } 
  }
}
